<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 
 */
class Sys extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->helper("common");
	}


	public function cache_flush(){
		cache_flush();
	}

	// 
	public function dev2live_do(){
		// $dev_c = array();
		// $live_c = array();

		// $dev_c['hostname'] = "db-pg1.cljrcpxo2wci.ap-southeast-1.rds.amazonaws.com";
		// $dev_c['username'] = "dev.lifebalanz";
		// $dev_c['password'] = "dC6*$dFn#Q";
		// $dev_c['database'] = "dev.lifebalanz";
		// $dev_c['dbdriver'] = "postgre";
		
		// $live_c['hostname'] = "db-pg1.cljrcpxo2wci.ap-southeast-1.rds.amazonaws.com";
		// $live_c['username'] = "live.lifebalanz";
		// $live_c['password'] = "x6oeBLiq4sWx";
		// $live_c['database'] = "live.lifebalanz";
		// $live_c['dbdriver'] = "postgre";

		$dev = $this->load->database("dev",true);
		$live = $this->load->database("live",true);

		// dev user_data
		$dev_data = $dev->query("select * from user_data")->result_array();
		
		if(is_array($dev_data)){
			var_dump(count($dev_data));
			$same = array();
			$dif = array();
			$insert = array();
			$values = '';
			foreach ($dev_data as $k => $v) {
				$rs = $live->query("select tid from user_data where tid=".$v['tid']." and date='".$v['date']."'")->row_array();
				
				if($rs){
					$same[] = $rs;
					continue;
				}else{
					$dif[] = $v;
					// 
					// $values =$v['tid'].",'".$v['date']."',".$v['lastupdate'].",'".$v['data']."'";
					// $r2 = $live->query("insert into user_data(tid,date,lastupdate,data) values(".$values.")");
					// $insert[] = $r2;
				}

				

			}

			// die;
			var_dump(count($same));
			var_dump(count($dif));
			var_dump(count($insert));
			// var_dump($dif);

			// if(!empty($dif)){
			// 	$values = '';
			// 	foreach ($dif as $k => $v) {
			// 		// $tid = $v['tid'];
			// 		// $date = "'".$v['date']."'";
			// 		// $lastupdate = $v['lastupdate'];
			// 		// $data = "'".$v['data']."'";
			// 		$values .=$v['tid'].",'".$v['date']."',".$v['lastupdate'].",'".$v['data']."',";
			// 	}
			// 	$values = trim($values,',');	

			// 	// var_dump($values);
			// 	// die;
			// 	$rs2 = $live->query("insert into user_data(tid,date,lastupdate,data) values(".$values.")");

			// 	var_dump($rs2);		
			// }


		}
	}
}